package com.youlu.campus.admin.university;
import com.youlu.campus.admin.utils.AuthUtils;
import com.youlu.campus.entity.UniversityActivityTaskRanking;
import com.youlu.campus.entity.VO.req.UniversityRankQueryVO;
import com.youlu.campus.service.ranking.UniversityActivityRankingService;
import com.yuelin.infrastructure.quantum.common.QResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import javax.validation.constraints.NotNull;

@RestController
public class UniversityRankController {
    @Autowired
    private UniversityActivityRankingService universityActivityRankingService;

    @PostMapping("/university/rank/list")
    public QResult list(@NotNull @RequestBody UniversityRankQueryVO request) {
        request.setUserId(AuthUtils.getUserId());
        Page<UniversityActivityTaskRanking> datas = universityActivityRankingService.list(request);
        return QResult.success(datas);
    }

    @PostMapping("/university/rank/update")
    public QResult update(@NotNull @RequestBody UniversityActivityTaskRanking request) {
        request.setOptUserId(AuthUtils.getUserId());
        boolean re = universityActivityRankingService.update(request);
        if (re) {
            return QResult.success(re);
        }
        return QResult.fail("no");
    }

    @GetMapping("/university/rank/find-one")
    public QResult findOne(@RequestParam("id") String id) {
        return QResult.success(universityActivityRankingService.findOne(id));
    }

    @GetMapping("/university/rank/delete")
    public QResult delete(@RequestParam("id") String id) {
        return QResult.success(universityActivityRankingService.delete(id));
    }
}
